package com.clickpaas.materialsprocurement.dao.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.codegen.StockinorderApi;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.SaveOrUpdateStockInOrderDTO;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.StockInOrderDTOUpdate;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.StockInOrderSaveOrUpdateDataResponseObject;
import com.clickpaas.materialsprocurement.bean.MateralsDTOBean;
import com.clickpaas.materialsprocurement.constant.ConstantFile;
import com.clickpaas.materialsprocurement.dao.StockInOrderDao;
import com.clickpaas.materialsprocurement.entity.StockInOrderEntity;
import com.clickpaas.materialsprocurement.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
@Slf4j
public class StockInOrderDaoImpl implements StockInOrderDao {
    @Resource
    private MateralsDTOBean materalsDtoBean;
    @Resource
    private StockinorderApi stockinorderApi;
    /**
     * 入库单
     *
     * @param stockInOrderEntity
     * @return boolean
     */
    @Override
    public boolean insertStockInOrderInfo(StockInOrderEntity stockInOrderEntity) {
        StockInOrderDTOUpdate stockInOrderDTOUpdate = materalsDtoBean.stockInOrderDTOUpdate();
        try {
            SpringUtil.copyPropertiesIgnoreNull(stockInOrderEntity,stockInOrderDTOUpdate);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",stockInOrderEntity);
        }
        SaveOrUpdateStockInOrderDTO saveOrUpdateStockInOrderDTO = new SaveOrUpdateStockInOrderDTO();
        saveOrUpdateStockInOrderDTO.setQuery(materalsDtoBean.stockInOrderDTOQuery());
        saveOrUpdateStockInOrderDTO.setUpdate(stockInOrderDTOUpdate);
        return insertData(saveOrUpdateStockInOrderDTO);
    }

    private Boolean insertData(SaveOrUpdateStockInOrderDTO saveOrUpdateStockInOrderDTO){
        try {
            StockInOrderSaveOrUpdateDataResponseObject dataResponseString = stockinorderApi.saveOrUpdateStockInOrderUsingPOST(saveOrUpdateStockInOrderDTO);
            if (null != dataResponseString
                    && ConstantFile._MESSAGE.equals(dataResponseString.getMessage())
                    && null != dataResponseString.getData())
                return true;
        }catch (Exception e){
            log.info("入库单数据失败：【{}】",e);
        }
        return false;
    }
}
